/*
 * PathContextTransferable.java
 *
 * Created on July 26, 2007, 1:31 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package dnbW.uiW.dbW;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

/**
 *
 * @author zhouyong
 */
public class PathContextTransferable
        implements Transferable {

    public static final String PATH_CONTEXT_FLAVOR_TYPE =
            DataFlavor.javaJVMLocalObjectMimeType +
            ";class=dnb.ui.db.PathContext";
    
    public static DataFlavor _pathContextFlavor;

    static {
        try {
            _pathContextFlavor = new DataFlavor(PATH_CONTEXT_FLAVOR_TYPE);
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
    }
    
    private PathContext _pathContext;
    private DataFlavor[] _supportedFlavors;

    /** Creates a new instance of PathContextTransferable */
    public PathContextTransferable(PathContext pathContext) {
        _pathContext = pathContext;
        _supportedFlavors = new DataFlavor[]{_pathContextFlavor};
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return _supportedFlavors;
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        if (flavor.equals(_pathContextFlavor)) {
            return true;
        }
        return false;
    }

    @Override
    public Object getTransferData(DataFlavor flavor)
            throws UnsupportedFlavorException, IOException {
        if (this.isDataFlavorSupported(flavor)) {
            return _pathContext;
        } else {
            throw new UnsupportedFlavorException(flavor);
        }
    }
}
